import EventEmitter from '../utils/EventEmitter'
import { RefObject } from 'react'
import { MusicPlayerSong } from '@/types/music'
import { AutoPlaySongController } from '@/lib/music/AutoPlaySongController'

type EmitterType = {
  /**
   * 当播放当前musicKey时触发
   * @param key
   * @returns
   */
  noteDown: (key: MusicKey) => any

  onKeyActive: (key: MusicKey, active: boolean) => any

  playerSong: (
    musicSong: MusicPlayerSong,
    ref: RefObject<AutoPlaySongController | null>
  ) => void

  onPlayerSongStop: (song: MusicPlayerSong) => void

  playSongTimeUpdate: (currentTime: number) => void

  songPause: (musicSong: MusicPlayerSong) => void
  songReplay: (musicSong: MusicPlayerSong, currentTime: number) => void

  loadSong: (musicSong: {
    value: MusicPlayerSong | null
    currentTime: number | null
  }) => void
}
export interface MusicKey {
  keyboard: string
  music: string
}
const pianoPlayerEvent = new EventEmitter<EmitterType>()

export default pianoPlayerEvent
